package ar.edu.unq.mongodbexample.homes;

import java.util.List;

import ar.edu.unq.mongodbexample.model.Univertity;
import ar.edu.unq.mongodbexample.persistence.MongoDBManager;

import com.google.code.morphia.dao.BasicDAO;

/**
 * @author CappaH
 * 
 */
/**
 * TODO: description
 */
public class UniversityHome extends BasicDAO<Univertity, Integer> implements IHome<Univertity> {

    public UniversityHome() {
        super(Univertity.class, MongoDBManager.getInstance().getDataStore());
        MongoDBManager.getInstance().getMorphia().map(Univertity.class);
    }

    public int saveAll(final List<Univertity> universities) {
        int notSaved = 0;
        for (Univertity university : universities) {
            try {
                this.save(university);
            } catch (Exception e) {
                // TODO: handle exception
                notSaved++;
            }
        }
        return notSaved;
    }

    public List<Univertity> getAll() {
        return this.ds.find(Univertity.class).asList();
    }

    public Univertity findById(final Object id) {
        return this.ds.get(Univertity.class, id);
    }
}
